import { ref } from 'vue'
import { useEventBus } from '@vueuse/core'

export default function useSort() {
  const sort_list = [
    { title: '默认', value: 'default' },
    { title: '价格升序', value: 'price_up' },
    { title: '价格降序', value: 'price_down' },
    { title: '销量升序', value: 'sales_up' },
    { title: '销量降序', value: 'sales_down' },
  ]
  const sort = ref('default')
  const bus = useEventBus('search')

  watch(sort, () => {
    bus.emit({ sort })
  })

  return {
    sort_list,
    sort,
  }
}